package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.NewProductRequest;
import com.ytjj.qmyx.admin.model.request.ProductSubjectPlateRequest;
import com.ytjj.qmyx.admin.model.request.SubjectsRequest;
import com.ytjj.qmyx.admin.model.response.ProductSubjectPlateResponse;
import com.ytjj.qmyx.admin.model.response.SubjectPlateResponse;
import com.ytjj.qmyx.admin.model.response.SubjectsResponse;
import com.ytjj.qmyx.admin.service.ProductService;
import com.ytjj.qmyx.admin.service.SubjectsService;
import com.ytjj.qmyx.mall.model.ProductSubjectPlate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 
 * 
 * @description:专题相关
 */
@RestController
@RequestMapping("/subjectsController")
public class SubjectsController {

    @Autowired
    private SubjectsService subjectsService;

    @Autowired
    private ProductService productService;

    /**
    * 添加或修改专题
    * @param subjectsRequest:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @PostMapping("/addOrEditSubject")
    public CommonResult addOrEditSubject(@RequestBody SubjectsRequest subjectsRequest) {
        boolean b = subjectsService.addOrEditSubject(subjectsRequest);
        return b ? CommonResult.success() : CommonResult.failed();
    }

    /** 
    * 根据专题Id获得专题信息
    * @param id: 
    * @returns: com.ytjj.common.api.CommonResult 
    * 
    */
    @GetMapping("/getSubjectInfo/{id}")
    public CommonResult getSubjectInfo(@PathVariable Integer id){
        return CommonResult.success(subjectsService.getSubjectInfo(id));
    }


    /**
    * 分页查询获得专题列表
    * @param subjectsRequest:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @PostMapping("/getSubject")
    public CommonResult getSubject(@RequestBody SubjectsRequest subjectsRequest){
        CommonPage<SubjectsResponse> subject = subjectsService.getSubject(subjectsRequest);
        return CommonResult.success(subject);
    }


    /**
    * 根据专题Id获得板块分页列表
    * @param :
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/getSubjectById/{id}")
    public CommonResult getSubjectById(@PathVariable Integer id){
        CommonPage<SubjectPlateResponse> plateBySubjectId = subjectsService.getPlateBySubjectId(id);
        return CommonResult.success(plateBySubjectId);
    }

    /**
    * 删除专题
    * @param id:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/delSubject/{id}")
    public CommonResult delSubject(@PathVariable Integer id){
        boolean b = subjectsService.delSubjectById(id);
        return b ? CommonResult.success() : CommonResult.failed();
    }

    /**
    * 添加或者编辑商品到板块
    * @param :
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @PostMapping("/addOrEditProductToPlate")
    public CommonResult addOrEditProductToPlate(@RequestBody ProductSubjectPlate productSubjectPlate){
        return CommonResult.success(subjectsService.addProduct(productSubjectPlate));
    }

    /** 
    * 查看板块下的商品
    * @param : 
    * @returns: com.ytjj.common.api.CommonResult 
    * 
    */
    @PostMapping("/getProductByPlateId")
    public CommonResult getProductByPlateId(@RequestBody ProductSubjectPlateRequest productSubjectPlateRequest){
        return CommonResult.success(subjectsService.getProductByPlateId(productSubjectPlateRequest));
    }

    /**
    * 移除板块
    * @param id:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/delPlateById/{id}")
    public CommonResult delPlateById(@PathVariable Integer id){
        boolean b = subjectsService.delPlateById(id);
        return b ? CommonResult.success() : CommonResult.failed();
    }

    /**
    * 移除商品
    * @param id:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @GetMapping("/delProductById/{id}")
    public CommonResult delProductById(@PathVariable Integer id){
        boolean b = subjectsService.delProductById(id);
        return b ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 获得编辑商品数据
     * @param id:
     * @returns: com.ytjj.common.api.CommonResult
     * 
     */
    @GetMapping("/getProductEditInfo/{id}")
    public CommonResult getProductEditInfo(@PathVariable Integer id){
        ProductSubjectPlateResponse productEditInfo = subjectsService.getProductEditInfo(id);
        return  CommonResult.success(productEditInfo);
    }

    /**
    * 查询不在板块商品表的商品
    * @param newProductRequest:
    * @returns: com.ytjj.common.api.CommonResult
    * 
    */
    @PostMapping("/getProductNotInSubject")
    public CommonResult getSmallProductList(@RequestBody NewProductRequest newProductRequest) {
        return CommonResult.success(productService.getProductNotInSubject(newProductRequest));
    }

}
